package com.zhentao.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zhentao.common.Result;
import com.zhentao.domain.SysActivity;
import com.zhentao.domain.SysActivityRecord;
import com.zhentao.domain.dto.PageDto;
import com.zhentao.service.SysActivityRecordService;
import com.zhentao.service.SysActivityService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/activity")
@Tag(name = "活动管理")
public class ActivityController {
    @Autowired
    private SysActivityService sysActivityService;
    @Autowired
    private SysActivityRecordService sysActivityRecordService;
//    活动增上改查
//    查询
    @PostMapping("/activelist")
    @Operation(summary = "活动列表")
    public Result getActivityList(@RequestBody PageDto pageDto){
        Page<SysActivity> sysActivityPage = sysActivityService.queryActivityByPage(pageDto);
        return Result.build(sysActivityPage,200,"查询成功");
    }
//    添加
    @PostMapping("/sativesave")
    @Operation(summary = "添加活动")
    public Result saveActivity(@RequestBody SysActivity activity){
        int i = sysActivityService.addActivity(activity);
        return Result.build(i,200,"添加成功");
    }
//    修改
    @PostMapping("/activeupdate")
    @Operation(summary = "修改活动")
    public Result updateActivity(@RequestBody SysActivity activity){
        int i = sysActivityService.updateActivity(activity);
        return Result.build(i,200,"修改成功");
    }
//    删除
    @DeleteMapping("/activeDelete")
    @Operation(summary = "删除活动")
    public Result deleteActivity(Integer id){
        int i = sysActivityService.deleteActivity(id);
        return Result.build(i,200,"删除成功");
    }
 //用户活动领取记录列表
    @PostMapping("/getActivityRecordList")
    @Operation(summary = "用户活动领取记录列表")
    public Result getActivityRecordList(@RequestBody PageDto pageDto){
        Page<SysActivityRecord> sysActivityRecordPage = sysActivityRecordService.queryActivityRecordByPage(pageDto);
        return Result.build(sysActivityRecordPage,200,"查询成功");
    }
}
